home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / biged.zip / LINES.PAS < prev   
Pascal/Delphi Source File  |  1990-12-09  |  3KB  |  133 lines

  1. unit Lines;
  2.  
  3. interface
  4.  
  5. uses
  6.   OpInline,
  7.   OpRoot,
  8.   OpString;
  9.  
  10. const
  11.   IsBlocked = $0001;
  12.   IsMarked  = $0002;
  13.  
  14. type
  15.   StrPtr = ^String;
  16.   LinePtr = ^LineNode;
  17.   LineNode =
  18.     object(DoubleListNode)
  19.       St : StrPtr;
  20.       Flags : Word;
  21.  
  22.       constructor Init(S : String);
  23.         {-init object}
  24.       destructor  Done; virtual;
  25.         {-dispose of it when finished}
  26.       procedure lnUpdate(NewS : String);
  27.         {-update the string pointer in the node to the new string}
  28.       function  lnReturn : String;
  29.         {-return the contents of the string}
  30.       function  lnLen : Byte;
  31.         {-return the length of the stored string}
  32.       function  lnFlagsAreOn(Options : Word) : Boolean;
  33.         {-true if all flag bits specified in Options are set}
  34.       procedure lnFlagsOn(Options : Word);
  35.         {-turn on one or more flag bits}
  36.       procedure lnFlagsOff(Options : Word);
  37.         {-turn off one or more flag bits}
  38.     end;
  39.  
  40.   LineList =
  41.     object(DoubleList)
  42.       function Num(P : DoubleNodePtr) : Word;
  43.         {-return the position in the list of P}
  44.       procedure Clean;
  45.         {-clear the list of all nodes}
  46.     end;
  47.  
  48.  
  49.  
  50. implementation
  51.  
  52.   constructor LineNode.Init(S : String);
  53.   begin
  54.     if NOT DoubleListNode.Init then Fail;
  55.     St := StrPtr(StringToHeap(S));
  56.     Flags := 0;
  57.   end;
  58.  
  59.   destructor LineNode.Done;
  60.   begin
  61.     DisposeString(Pointer(St));
  62.     DoubleListNode.Done;
  63.   end;
  64.  
  65.   procedure LineNode.lnUpdate(NewS : String);
  66.   begin
  67.     DisposeString(Pointer(St));
  68.     St := StrPtr(StringToHeap(TrimTrail(NewS)));
  69.   end;
  70.  
  71.   function LineNode.lnReturn : String;
  72.   begin
  73.     lnReturn := St^;
  74.   end;
  75.  
  76.   function LineNode.lnLen : Byte;
  77.   begin
  78.     lnLen := Byte(St^[0]);
  79.   end;
  80.  
  81.   function LineNode.lnFlagsAreOn(Options : Word) : Boolean;
  82.   begin
  83.     lnFlagsAreOn := FlagIsSet(Flags,Options);
  84.   end;
  85.  
  86.   procedure LineNode.lnFlagsOn(Options : Word);
  87.   begin
  88.     SetFlag(Flags,Options);
  89.   end;
  90.  
  91.   procedure LineNode.lnFlagsOff(Options : Word);
  92.   begin
  93.     ClearFlag(Flags,Options);
  94.   end;
  95.  
  96. {----------------------------------------------------}
  97.  
  98.   function LineList.Num(P : DoubleNodePtr) : Word;
  99.   var W : Word;
  100.       N : DoubleNodePtr;
  101.   begin
  102.     Num := 0;
  103.     if P = nil then exit;
  104.     W := 1;
  105.     N := dlHead;
  106.     while (N <> P) do begin
  107.       Inc(W);
  108.       N := N^.dlNext;
  109.       if N = nil then exit;
  110.     end;
  111.     Num := W;
  112.   end;
  113.  
  114.   procedure LineList.Clean;
  115.   var N : DoubleNodePtr;
  116.       P : DoubleNodePtr;
  117.   begin
  118.     N := dlTail;
  119.     while N <> nil do begin
  120.       P := N^.dlPrev;
  121.       if OS(N).S >= OS(HeapOrg).S then
  122.         Dispose(N, Done)
  123.       else
  124.         N^.Done;
  125.       N := P;
  126.     end;
  127.     dlTail := nil;
  128.     dlHead := nil;
  129.     dlSize := 0;
  130.   end;
  131.  
  132. end.
  133.